package com.jspgou.cms.dao.impl;

import java.util.List;

import org.hibernate.Criteria;
import org.springframework.stereotype.Repository;

import com.jspgou.common.hibernate3.Finder;
import com.jspgou.common.hibernate3.HibernateBaseDao;
import com.jspgou.common.page.Pagination;
import com.jspgou.cms.dao.ShopPaymentorderDao;
import com.jspgou.cms.entity.ShopPaymentorder;

@Repository
public class ShopPaymentorderDaoImpl extends HibernateBaseDao<ShopPaymentorder, Long> implements ShopPaymentorderDao {
	public Pagination getPage(int pageNo, int pageSize) {
		Criteria crit = createCriteria();
		Pagination page = findByCriteria(crit, pageNo, pageSize);
		return page;
	}

	public ShopPaymentorder findById(Long id) {
		ShopPaymentorder entity = get(id);
		return entity;
	}
	
	@SuppressWarnings("unchecked")
	public ShopPaymentorder findByCode(String code){
		Finder f=Finder.create("from ShopPaymentorder bean where bean.code=:code").setParam("code", code);
		List<ShopPaymentorder> list=find(f);
		if(list.size()==1){
			return list.get(0);
		}else{
			return null;
		}
	}

	public ShopPaymentorder save(ShopPaymentorder bean) {
		getSession().save(bean);
		return bean;
	}

	public ShopPaymentorder deleteById(Long id) {
		ShopPaymentorder entity = super.get(id);
		if (entity != null) {
			getSession().delete(entity);
		}
		return entity;
	}
	
	@Override
	protected Class<ShopPaymentorder> getEntityClass() {
		return ShopPaymentorder.class;
	}
}